using System;
using Firestarter.Test.Base;
using FireStarterModeller.BO;
using Habanero.Base;
using Habanero.BO;
using NUnit.Framework;

namespace FireStarterModeller.Test.BO
{
    [TestFixture]
    public class TestDMPropertyNameDoesNotStartWithNumber
    {
        [SetUp]
        public void SetupTest()
        {
            //Runs every time that any testmethod is executed
            TestUtilsDomain.SetupTest();
            BORegistry.DataAccessor = new DataAccessorInMemory();
        }

        [TestFixtureSetUp]
        public void TestFixtureSetup()
        {
            //Code that is executed before any test is run in this class. If multiple tests
            // are executed then it will still only be called once.
            TestUtilsDomain.SetupFixture();
        }

        [TearDown]
        public void TearDownTest()
        {
            //runs every time any testmethod is complete
        }

        #region TestDMPropertyNameDoesNotStartWithNumber

        [Test]
        public void Test_CreateDMPropertyNameDoesNotStartWithNumber()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = TestUtilsDMProperty.CreateUnsavedDefaultDMProperty();
            dmProperty.PropertyName = TestUtilsShared.GetRandomString();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IBusinessObjectRule rule = new DMPropertyNameDoesNotStartWithNumberRule();
            //---------------Test Result -----------------------
            Assert.IsNotNull(rule);
            Assert.AreEqual("DMPropertyNameDoesNotStartWithNumber", rule.Name);
            Assert.AreEqual(ErrorLevel.Error, rule.ErrorLevel);
        }

//        [Test]
//        public void Test_CreateDMPropertyNameDoesNotStartWithNumber_WhenDMPropertyNull_ShouldRaiseError()
//        {
//            //---------------Set up test pack-------------------
//            //---------------Assert Precondition----------------
//            //---------------Execute Test ----------------------
//            try
//            {
//                new DMPropertyNameDoesNotStartWithNumberRule(null);
//                Assert.Fail("expected ArgumentNullException");
//            }
//                //---------------Test Result -----------------------
//            catch (ArgumentNullException ex)
//            {
//                StringAssert.Contains("Value cannot be null", ex.Message);
//                StringAssert.Contains("dmProperty", ex.ParamName);
//            }
//        }

        [Test]
        public void Test_DMPropertyNameDoesNotStartWithNumber_FailsWhenPropertyNameStartsWithNumber()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = TestUtilsDMProperty.CreateUnsavedDefaultDMProperty();
            dmProperty.PropertyName = "2e5ete$#$^";
            IBusinessObjectRule rule = new DMPropertyNameDoesNotStartWithNumberRule();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            bool isValid = rule.IsValid(dmProperty);
            //---------------Test Result -----------------------
            Assert.IsFalse(isValid);
            StringAssert.Contains("The Property Name '", rule.Message);
            StringAssert.Contains("'" + dmProperty.PropertyName + "'", rule.Message);
            StringAssert.Contains("' on Class '" + dmProperty.Class + "' cannot start with a number.", rule.Message);
        }

        [Test]
        public void Test_DMPropertyNameDoesNotStartWithNumber_PassesWhenPropertyNameDoesNotStartWithNumber()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = TestUtilsDMProperty.CreateUnsavedDefaultDMProperty();
            dmProperty.PropertyName = "sdg$ ^$##";
            IBusinessObjectRule rule = new DMPropertyNameDoesNotStartWithNumberRule();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            bool isValid = rule.IsValid(dmProperty);
            //---------------Test Result -----------------------
            Assert.IsTrue(isValid);
        }

        [Test]
        public void Test_DMPropertyNameDoesNotStartWithNumber_PassesWhenPropertyNameIsNull()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = TestUtilsDMProperty.CreateUnsavedDefaultDMProperty();
            dmProperty.PropertyName  = null;
            IBusinessObjectRule rule = new DMPropertyNameDoesNotStartWithNumberRule();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            bool isValid = rule.IsValid(dmProperty);
            //---------------Test Result -----------------------
            Assert.IsTrue(isValid);
        }

        [Test]
        public void Test_DMPropertyNameDoesNotStartWithNumber_PassesWhenPropertyNameIsEmpty()
        {
            //---------------Set up test pack-------------------
            DMProperty dmProperty = TestUtilsDMProperty.CreateUnsavedDefaultDMProperty();
            dmProperty.PropertyName =  "";
            IBusinessObjectRule rule = new DMPropertyNameDoesNotStartWithNumberRule();
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            bool isValid = rule.IsValid(dmProperty);
            //---------------Test Result -----------------------
            Assert.IsTrue(isValid);
        }

        #endregion

    }
}